package main

import (
	"fmt"
	"github.com/lxn/walk"
	"math/rand"
	"time"
)

type Foo struct {
	Index   int
	//协议
	agr     string
	address    string
	outAddress    string
	pid     string
	state   string
	serviceName string
    port    string
	memory  string


}

type FooModel struct {
	walk.TableModelBase
	walk.SorterBase

	sortColumn int
	sortOrder  walk.SortOrder
	items      []*Foo
}

func NewFooModel() *FooModel {
	m := new(FooModel)
	return m
}

// Called by the TableView from SetModel and every time the model publishes a
// RowsReset event.
func (m *FooModel) RowCount() int {
	return len(m.items)
}

// Called by the TableView when it needs the text to display for a given cell.
func (m *FooModel) Value(row, col int) interface{} {
	item := m.items[row]
	switch col {
	case 0:
		return item.Index

	case 1:
		return item.agr

	case 2:
		return item.address
	case 3:
		return item.outAddress

	case 4:
		return item.state
	case 5:
		return item.pid
	case 6:
		return item.serviceName
	case 7:
		return item.port
	case 8:
		return item.memory
	}

	panic("unexpected col")
}



func (m *FooModel) addOrqc() {
	m.items = make([]*Foo, rand.Intn(10))

}

func emptyTable(m *FooModel)  {
	items := m.items
	for i := 0; i <len(items) ; i++ {
		foo := items[0]
		killPort(foo)
	}

	m.items = make([]*Foo, 0)
	m.PublishRowsReset()
}





func (m *FooModel) ResetRows() {
	// Create some random data.
	m.items = make([]*Foo, 10)

	now := time.Now()
	fmt.Println(now)
	for i := range m.items {
		m.items[i] = &Foo{
			Index: i,
			agr:"tcp",
			address:"127.0.0.1",
			pid:"pid",
			state:"状态",
			serviceName:"服务名字",
			port:"端口",
			memory:"内存占用",
		}
	}

	m.PublishRowsReset()
}



